<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Track_model extends CI_Model 
{ 
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    public function track_activity($label = '', $value = '') {
        //echo 'tracking: ' . $label . '-' . $value;
        $tracking_list = $this->db->get_where(
            'psacar_tracking',
            array('label' => $label, 'value' => $value));
        
        $tracking_id = 0;
        $counter = 0;
        foreach($tracking_list->result() as $tracking)
        {
            $tracking_id = $tracking->id;
            $counter = $tracking->counter;;
        }
        
        $counter += 1;
        $tracking = array(
            'label' => $label,
            'value' => $value,
            'counter' => $counter);
        if($tracking_id == 0)
            $this->db->insert('psacar_tracking', $this->security->xss_clean($tracking));
        else
        {
            $this->db->where('id', $tracking_id);
            $this->db->update('psacar_tracking', $tracking);        
        }        
    }	    
}